define(function (require, exports, module) {
    'use strict';
    var $ = require('jquery'),
        _ = require('underscore'),
        Backbone = require('backbone'),
        notify = require('js/utils/notify'),
        utils = require('js/utils/tools'),
        helper = require('js/apps/report/common');

    var StrategyGameView = Backbone.View.extend({
        events: {
            'click a.onClickSaveDebug': 'saveDebug',
        },
        initialize: function (options) {
            this.options = options;
            this.s_dict = {};
        },
        saveDebug: function (e) {
            var valid = true;
            var cells = $(e.currentTarget).closest('tr').find("td");
            var game_key = $(cells[1]).find("input").val();
            var value = $(cells[2]).find("input").val();
            var ttl = parseInt($(cells[3]).find("input").val());
            if (!(game_key) || !(value) || !(ttl)) {
                notify.error('错误', '参数不能为空!');
                valid = false;
                return;
            }
            var confs = {
                "game_key": game_key,
                "value": value,
                "ttl": ttl
            };
            console.log(confs);
            $.post('/admin/strategy/game/set/', JSON.stringify(confs)).done(function (resp) {
                var data = resp.data;
                notify.success('提示', '保存成功！');
            }).fail(function (data) {
                notify.notifyResp(data);
            });
        },
        render: function () {
            this.$el.html("");
            $(window).scrollTop(0);
            return this;
        },
        renderWithData: function () {
            this.$el.html(this.template({
                s_dict: this.s_dict,
                options: this.options,
            }));
            return this;
        },
        load: function () {
            var that = this;
            $.get('/admin/strategy/game/get/').done(function (resp) {
                that.s_dict = resp.data.dict;
                that.renderWithData();
            }).fail(function (data) {
                notify.notifyResp(data);
            });
        }
    });
    exports.List = Backbone.View.extend({
        el: "#content_wrapper",
        template: "op/StrategyList.html",
        render: function () {
            var view = new StrategyGameView({
            });
            view.template = this.template;
            this.$el.empty();
            this.$el.append(view.render().el);
            view.load();
            return this;
        }
    });

});
